﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;

namespace ConsoleApplication2
{
    class Program
    {
        static bool IfPrime(int n)
        {
            bool flag = true;
            for(int i=2;i<= n/2; i++)
            {
                if (n % i == 0)
                {
                    flag = false;
                    break;
                }
            }
            return flag;
        }

        static void Main(string[] args)
        {
            while (true)
            {
                int num;
                int i = 2;
                Write("输入你想检验的自然数：");
                num = Int32.Parse(ReadLine());
                Write("素数因子为：");
                int x = num / 2;
                if (IfPrime(num))
                {
                    Write(num);
                    WriteLine();
                    continue;
                }
                while (i<=x)
                {
                    if (IfPrime(i)==true && num % i == 0)
                    {
                        Write(i+" ");
                        num = num / i;
                    }
                    else if (IfPrime(i) == false||num%i!=0)
                    {
                        i++;
                    }
                }
                //Write(num);
                WriteLine();
            }
        }
    }
}
